package cn.com.dhcc.app.pub.core.listener;

import javax.servlet.ServletContextEvent;

import cn.com.dhcc.app.core.CM;
import cn.com.dhcc.app.core.boot.BootParam;
import cn.com.dhcc.app.core.exception.InitException;
import cn.com.dhcc.app.core.listener.AppInitListener;
import cn.com.dhcc.app.pub.core.consts.NodeInfoParam;
import cn.com.dhcc.turbo.service.queue.tlq.TlqOptService;

import com.tongtech.tlq.admin.dynamic.ConstDefine;

/**
 * 初始化TLQ配置	
 */
public class TlqInitListener implements AppInitListener {
	//private static Logger logger = Log.getLogger(LOGTYPE.TLQ);

	@Override
	public void init(ServletContextEvent contextEvent, BootParam bootParam) throws InitException {
		boolean isMaster = NodeInfoParam.isMaster();
		//TODO 目前只有主节点才能启动tlq监听
		if(isMaster){
			contextEvent.getServletContext().log("开始TLQ连接和监听...");
			TlqOptService tlqOptService = CM.getBean(TlqOptService.class);
			tlqOptService.initTlqQcuAndRecvQueue();
			contextEvent.getServletContext().log("TLQ 连接成功.");
			contextEvent.getServletContext().log("ConstDefine.logDebug:"+ConstDefine.logDebug);
		}else{
			contextEvent.getServletContext().log("当前节点为slave节点,不启动tlq监听...");
		}
	}

	@Override
	public void destroyed(ServletContextEvent contextEvent, BootParam bootParam) throws Exception {
	}
}
